package organization

import (
	"context"
	"gitee.com/zyw0605688_admin/gozero/organization/pb/organizationPb"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"log"

	"gitee.com/zyw0605688_admin/gozero/user/internal/svc"
	"gitee.com/zyw0605688_admin/gozero/user/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DepartmentCreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDepartmentCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DepartmentCreateLogic {
	return &DepartmentCreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DepartmentCreateLogic) DepartmentCreate(req *types.DepartmentCreateRequest) (resp *types.DepartmentCreateResponse, err error) {
	conn, err := grpc.Dial("127.0.0.1:3002", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Println(err)
		return
	}
	client := organizationPb.NewOrganizationClient(conn)
	res, err := client.DepartmentCreate(l.ctx, &organizationPb.DepartmentCreateRequest{
		DepartmentName: req.DepartmentName,
		DepartmentCode: req.DepartmentCode,
		DepartmentDesc: req.DepartmentDesc,
	})
	resp = &types.DepartmentCreateResponse{
		DepartmentId:   res.DepartmentId,
		DepartmentName: res.DepartmentName,
		DepartmentCode: res.DepartmentCode,
		DepartmentDesc: res.DepartmentDesc,
	}
	return
}
